import Vue from 'vue'
import App from './App.vue'
import router from './router'
// 在main.js引入qs
import qs from 'qs'
import './assets/globla.css'
// import './plugins/element.js'
import 'lib-flexible'
import axios from 'axios'
import md5 from 'js-md5'
Vue.prototype.$md5 = md5
require('./mock/index.js')

Vue.prototype.$http = axios
Vue.config.productionTip = false

const on = Vue.prototype.$on
// 防抖处理
Vue.prototype.$on = function (event, func) {
  let timer
  let newFunc = func
  if (event === 'click') {
    newFunc = function () {
      clearTimeout(timer)
      timer = setTimeout(function () {
        func.apply(this, arguments)
      }, 500)
    }
  }
  on.call(this, event, newFunc)
}
// 节流
Vue.prototype.$on = function (event, func) {
  let previous = 0
  let newFunc = func
  if (event === 'click') {
    newFunc = function () {
      const now = new Date().getTime()
      if (previous + 3000 <= now) {
        func.apply(this, arguments)
        previous = now
      }
    }
  }
  on.call(this, event, newFunc)
}

// 配全局属性配置，在任意组件内可以使用this.$qs获取qs对象
Vue.prototype.$qs = qs
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
